package com.huiminpay.merchant.controller;

import com.huiminpay.merchant.api.AppService;
import com.huiminpay.merchant.common.util.SecurityUtil;
import com.huiminpay.merchant.dto.AppDTO;
import com.huiminpay.transaction.api.PayChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 有点儿意思
 * @Description:
 */
@Api(tags = "商户应用接口")
@RestController
public class AppController {

    @Reference
    AppService appService;

    @Reference
    PayChannelService payChannelService;

    @ApiOperation("创建商户应用")
    @PostMapping("/my/apps")
    public AppDTO createApp(@RequestBody AppDTO appDTO){
        Long merchantId = SecurityUtil.getMerchantId();
        return appService.createApp(merchantId, appDTO);
    }

    @ApiOperation("根据appid获取应用详情")
    @GetMapping(value = "/my/apps/{appId}")
    public AppDTO getApp(@PathVariable String appId) {
        return appService.queryAppDetail(appId);
    }

    @ApiOperation("绑定服务类型")
    @PostMapping(value="/my/apps/{appId}/platform-channels")
    public void bindPlatformForApp(@PathVariable("appId") String appId,
                                   @RequestParam("platformChannelCodes") String platformChannelCodes){
        payChannelService.insertAppPlatformChannel(appId, platformChannelCodes);
    }

    @ApiOperation("查询应用是否绑定了某个服务类型")
    @GetMapping("/my/merchants/apps/platformchannels")
    public Integer queryAppBindPlatformChannel(@RequestParam("appId") String appId,
                                               @RequestParam("platformChannel") String platformChannelCode){
        return payChannelService.queryAppPlatformChannel(appId,platformChannelCode);
    }
}
